package com.jar.exercise.多线程.AQS.CountDownLatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        long begin = System.currentTimeMillis();
        final CountDownLatch countDownLatch = new CountDownLatch(2);
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
                System.out.println("我去支付医药费");
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                countDownLatch.countDown();
            }
        }).start();
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
                System.out.println("老婆去诊断病情");
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                countDownLatch.countDown();
            }
        }).start();

        System.out.println("带老婆去医院。。。loding");
//        countDownLatch.await(3,TimeUnit.SECONDS);
        countDownLatch.await();
        long end = System.currentTimeMillis();
        System.out.println("总共看病花费了：" + (end - begin));
        System.out.println();
    }
}
